import Vue from 'vue'
import Vuex from 'vuex'
import vuexpersist from "vuex-persist"

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    shopcar: []
  },
  mutations: {
    add(state, item) {
      var flag = false;
      state.shopcar.forEach((ele) => {
        if(ele.basicInfo.id==item.basicInfo.id){
          ele.num++
          flag=true
        }
      })
      if(!flag){
        item.num=1
        state.shopcar.push(item)
      }
    }
  },
  actions: {},
  modules: {},
  plugins: [
    new vuexpersist({
      storage: window.localStorage
    }).plugin
  ]
})